# models.py

from flask_sqlalchemy import SQLAlchemy


db = SQLAlchemy()

class User(db.Model):
    __tablename__ = 'users'
    userName = db.Column(db.String(64), unique=True, index=True,primary_key=True)
    pwd = db.Column(db.String(64))

    def __init__(self, userName, pwd):
        self.userName = userName
        self.pwd = pwd

class Level(db.Model):
    __tablename__ = 'level'
    listName = db.Column(db.String(64), primary_key=True,unique=True)
    subject = db.Column(db.String(64))
    total = db.Column(db.Integer)
    
    def __init__(self, listName, subject, total):
        self.listName = listName
        self.subject = subject
        self.total = total
        
class Vocabulary(db.Model):
    __tablename__ = 'vocabulary'
    en = db.Column(db.String(64), primary_key=True)
    zh = db.Column(db.String(512))
    
    def __init__(self, en, zh):
        self.en = en
        self.zh = zh
        
        
class Revised(db.Model):
    __tablename__ = 'revised'
    userName = db.Column(db.String(64), db.ForeignKey('users.userName'),primary_key=True)
    listName = db.Column(db.String(64), db.ForeignKey('level.listName'),primary_key=True)
    location = db.Column(db.BigInteger)
    startedAt = db.Column(db.BigInteger)
    updatedAt = db.Column(db.BigInteger)
    
    def __init__(self, userName, listName, location, startedAt, updatedAt):
        self.userName = userName
        self.listName = listName
        self.location = location
        self.startedAt = startedAt
        self.updatedAt = updatedAt
        
class Learned(db.Model):
    __tablename__ = 'learned'
    userName = db.Column(db.String(64),db.ForeignKey('users.userName') ,primary_key=True)
    en = db.Column(db.String(64), db.ForeignKey('vocabulary.en'),primary_key=True)
    period = db.Column(db.Integer)
    stage = db.Column(db.Integer)
    updatedAt = db.Column(db.BigInteger)
    
    def __init__(self, userName, en, period, stage, updatedAt):
        self.userName = userName
        self.en = en
        self.period = period
        self.stage = stage
        self.updatedAt = updatedAt

class Focus(db.Model):
    __tablename__ = 'focus'
    userName = db.Column(db.String(64),db.ForeignKey('users.userName') ,primary_key=True)
    play_frame = db.Column(db.Integer) 
    total_frame = db.Column(db.Integer)
    
    def __init__(self, userName, play_frame, total_frame):
        self.userName = userName
        self.play_frame = play_frame
        self.total_frame = total_frame

class Remark(db.Model):
    __tablename__ = 'remark'
    id = db.Column(db.Integer, primary_key = True)
    words = db.Column(db.String(128), primary_key = True)